//
//  BYAddNewAddressController.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/2/17.
//

#import "BYAddNewAddressController.h"
#import "BYTextField.h"

@interface BYAddNewAddressController ()<UITextFieldDelegate, UITextViewDelegate>

@property (nonatomic, strong) UILabel       *consignee;
@property (nonatomic, strong) BYTextField   *consigneeField;

@property (nonatomic, strong) UILabel       *phone;
@property (nonatomic, strong) BYTextField   *phoneField;

@property (nonatomic, strong) UILabel       *address;
@property (nonatomic, strong) UITextView    *addressField;

@property (nonatomic, strong) UIButton      *addButton;

@end

@implementation BYAddNewAddressController

#pragma mark - Event
- (void)addNewEvent {
    
}

#pragma mark - LifeCycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.consignee];
    [self.view addSubview:self.consigneeField];
    
    [self.view addSubview:self.phone];
    [self.view addSubview:self.phoneField];
    
    [self.view addSubview:self.address];
    [self.view addSubview:self.addressField];
    
    [self.view addSubview:self.addButton];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    [self.consignee mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(kAutoWithSize(10));
        make.left.equalTo(self.view).offset(kAutoWithSize(10));
        make.width.mas_equalTo(kAutoWithSize(80));
        make.height.mas_equalTo(kAutoWithSize(30));
    }];
    
    [self.consigneeField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.consignee.mas_right);
        make.centerY.equalTo(self.consignee);
        make.right.equalTo(self.view).offset(-kAutoWithSize(10));
        make.height.mas_equalTo(kAutoWithSize(30));
    }];
    
    [self.phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.consignee.mas_bottom).offset(kAutoWithSize(10));
        make.left.equalTo(self.consignee);
        make.width.mas_equalTo(kAutoWithSize(80));
        make.height.mas_equalTo(kAutoWithSize(30));
    }];

    [self.phoneField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.phone.mas_right);
        make.centerY.equalTo(self.phone);
        make.right.equalTo(self.consigneeField);
        make.height.mas_equalTo(kAutoWithSize(30));
    }];

    [self.address mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.phone.mas_bottom).offset(kAutoWithSize(10));
        make.left.equalTo(self.consignee);
        make.width.mas_equalTo(kAutoWithSize(80));
        make.height.mas_equalTo(kAutoWithSize(30));
    }];

    [self.addressField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.address);
        make.left.equalTo(self.address.mas_right);
        make.right.equalTo(self.phoneField);
        make.height.mas_equalTo(kAutoWithSize(150));
    }];

}


#pragma mark - LazyGet

- (UILabel *)consignee {
    if (!_consignee) {
        _consignee = [[UILabel alloc] init];
        _consignee.text = @"收货人";
    }
    return _consignee;
}

- (BYTextField *)consigneeField {
    if (!_consigneeField) {
        _consigneeField = [[BYTextField alloc] init];
        _consigneeField.delegate = self;
        _consigneeField.borderStyle = UITextBorderStyleLine;
        _consigneeField.backgroundColor = [UIColor whiteColor];
    }
    return _consigneeField;
}


- (UILabel *)phone {
    if (!_phone) {
        _phone = [[UILabel alloc] init];
        _phone.text = @"联系电话";
    }
    return _phone;
}

- (BYTextField *)phoneField {
    if (!_phoneField) {
        _phoneField = [[BYTextField alloc] init];
        _phoneField.delegate = self;
        _phoneField.borderStyle = UITextBorderStyleLine;
        _phoneField.backgroundColor = [UIColor whiteColor];
    }
    return _phoneField;
}

- (UILabel *)address {
    if (!_address) {
        _address = [[UILabel alloc] init];
        _address.text = @"详细地址";
    }
    return _address;
}

- (UITextView *)addressField {
    if (!_addressField) {
        _addressField = [[UITextView alloc] init];
        _addressField.delegate = self;
        _addressField.layer.borderWidth = 1.0f;
        _addressField.layer.borderColor = [UIColor blackColor].CGColor;
    }
    return _addressField;
}

- (UIButton *)addButton {
    if (!_addButton) {
        _addButton = [[UIButton alloc] initWithFrame:CGRectMake(kAutoWithSize(10), kScreenHeight-kSafeAreaTopHeight-kSafeAreaBottomHeight-kAutoWithSize(100)-kAutoWithSize(5), kScreenWidth-kAutoWithSize(20), kAutoWithSize(40))];
        [_addButton setTitle:@"新建地址" forState:UIControlStateNormal];
        [_addButton setBackgroundColor:PUBLIC_ORANGE_COLOR forState:UIControlStateNormal];
        [_addButton setBackgroundColor:PUBLIC_ORANGE_COLOR forState:UIControlStateSelected];
        [_addButton setViewCornerRadius:kAutoWithSize(8)];
        [_addButton addTarget:self action:@selector(addNewEvent) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addButton;
}




@end
